package cn.xscrum.vtsp.controller;

import java.util.Date;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.vtsp.domain.VtspAppraise;
import cn.xscrum.vtsp.service.IVtspAppraiseService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 志愿者评价信息Controller
 * 
 * @author xscrum
 * @date 2021-10-01
 */
@Controller
@RequestMapping("/vtsp/appraise")
public class VtspAppraiseController extends BaseController
{
    private String prefix = "vtsp/appraise";

    @Autowired
    private IVtspAppraiseService vtspAppraiseService;

    @RequiresPermissions("vtsp:appraise:view")
    @GetMapping()
    public String appraise()
    {
        return prefix + "/appraise";
    }

    /**
	 * 查询志愿者评价信息列表
     */
    @RequiresPermissions("vtsp:appraise:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VtspAppraise vtspAppraise)
    {
        startPage();
        if(vtspAppraise.getEndDate() != null) {
            long timeStamp = vtspAppraise.getEndDate().getTime();
            timeStamp += (24 * 60 * 60 - 1) * 1000;
            vtspAppraise.setEndDate(new Date(timeStamp));
        }
        List<VtspAppraise> list = vtspAppraiseService.selectVtspAppraiseList(vtspAppraise);
        return getDataTable(list);
    }

    /**
	 * 导出志愿者评价信息列表
     */
    @RequiresPermissions("vtsp:appraise:export")
    @Log(title = "志愿者评价信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VtspAppraise vtspAppraise)
    {
        List<VtspAppraise> list = vtspAppraiseService.selectVtspAppraiseList(vtspAppraise);
        ExcelUtil<VtspAppraise> util = new ExcelUtil<VtspAppraise>(VtspAppraise.class);
        return util.exportExcel(list, "appraise");
    }

    /**
	 * 新增志愿者评价信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存志愿者评价信息
     */
    @RequiresPermissions("vtsp:appraise:add")
    @Log(title = "志愿者评价信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VtspAppraise vtspAppraise)
    {
        return toAjax(vtspAppraiseService.insertVtspAppraise(vtspAppraise));
    }

    /**
	 * 修改志愿者评价信息
     */
    @GetMapping("/edit/{appraiseId}")
    public String edit(@PathVariable("appraiseId") Long appraiseId, ModelMap mmap)
    {
        VtspAppraise vtspAppraise = vtspAppraiseService.selectVtspAppraiseById(appraiseId);
        mmap.put("vtspAppraise", vtspAppraise);
        return prefix + "/edit";
    }

    /**
	 * 修改保存志愿者评价信息
     */
    @RequiresPermissions("vtsp:appraise:edit")
    @Log(title = "志愿者评价信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VtspAppraise vtspAppraise)
    {
        return toAjax(vtspAppraiseService.updateVtspAppraise(vtspAppraise));
    }

    /**
	 * 删除志愿者评价信息
     */
    @RequiresPermissions("vtsp:appraise:remove")
    @Log(title = "志愿者评价信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(vtspAppraiseService.deleteVtspAppraiseByIds(ids));
    }

}
